﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace QuanLyTiemVang.Classes
{
    class Exporter
    {
        public void ExportToExcel(DataGrid dgDisplay)
        {
            dgDisplay.SelectAllCells();
            dgDisplay.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
            ApplicationCommands.Copy.Execute(null, dgDisplay);
            String resultat = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
            String result = (string)Clipboard.GetData(DataFormats.Text);
            dgDisplay.UnselectAllCells();
            //StreamWriter file = new StreamWriter(@"C:\Users\test.xls", Encoding.Unicode);
            FileStream fs = new FileStream(@"C:\Users\test.xls", FileMode.Create);
            StreamWriter file = new StreamWriter(fs, Encoding.ASCII);
            file.WriteLine(result.Replace(',', ' '));
            file.Close();

            MessageBox.Show("Exporting DataGrid data to Excel file created");
        }

       
    }
}
